package com.ruoyi.project.poem.subject.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.subject.domain.PkSubject;
import com.ruoyi.project.poem.subject.service.IPkSubjectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 诗词考题Controller
 * 
 * @author shixiangwen
 * @date 2019-12-27
 */
@Controller
@RequestMapping("/poem/subject")
public class PkSubjectController extends BaseController {
	private String prefix = "poem/subject";

	@Autowired
	private IPkSubjectService pkSubjectService;

	@RequiresPermissions("poem:subject:view")
	@GetMapping()
	public String subject() {
		return prefix + "/subject";
	}

	/**
	 * 查询诗词考题列表
	 */
	@RequiresPermissions("poem:subject:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PkSubject pkSubject) {
		startPage();
		List<PkSubject> list = pkSubjectService.selectPkSubjectList(pkSubject);
		return getDataTable(list);
	}

	/**
	 * 导出诗词考题列表
	 */
	@RequiresPermissions("poem:subject:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(PkSubject pkSubject) {
		List<PkSubject> list = pkSubjectService.selectPkSubjectList(pkSubject);
		ExcelUtil<PkSubject> util = new ExcelUtil<PkSubject>(PkSubject.class);
		return util.exportExcel(list, "subject");
	}

	/**
	 * 新增诗词考题
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存诗词考题
	 */
	@RequiresPermissions("poem:subject:add")
	@Log(title = "诗词考题", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PkSubject pkSubject) {
		return toAjax(pkSubjectService.insertPkSubject(pkSubject));
	}

	/**
	 * 修改诗词考题
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		PkSubject pkSubject = pkSubjectService.selectPkSubjectById(id);
		mmap.put("pkSubject", pkSubject);
		return prefix + "/edit";
	}

	/**
	 * 修改保存诗词考题
	 */
	@RequiresPermissions("poem:subject:edit")
	@Log(title = "诗词考题", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PkSubject pkSubject) {
		return toAjax(pkSubjectService.updatePkSubject(pkSubject));
	}

	/**
	 * 删除诗词考题
	 */
	@RequiresPermissions("poem:subject:remove")
	@Log(title = "诗词考题", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(pkSubjectService.deletePkSubjectByIds(ids));
	}
}
